“No renderer backend detected. gganimate will default to writing frames to separate files Consider installing: - the gifski package for gif output - the av package for video output and restarting the R session”
source(here("functions", "theme_pepe.R"))
ts_data <- read_csv(here("data", "time_series.csv"))
## Parsed with column specification:
## cols(
## .default = col_double(),
## sample_id = col_character(),
## site_id = col_character(),
## collected_by = col_character(),
## sampling_date = col_date(format = ""),
## sampling_time = col_character(),
## samp_date_time = col_datetime(format = ""),
## treatment = col_character(),
## batch = col_character(),
## submission_date = col_date(format = ""),
## analysis_date_time = col_character(),
## compound = col_character()
## )
## See spec(...) for full column specifications.
ts_data <- ts_data %>%
mutate(treatment = factor(treatment, levels = c("Low", "Medium", "High")))
figure_1 <- ts_data %>%
filter( compound == "compound_1") %>%
ggplot() +
geom_point(aes(x = samp_date_time, y = concentration, colour = treatment)) +
theme_pepe() +
# ggannimate sections
labs(x = NULL,
y = "Concentration",
title = 'date: {frame_time}') +
transition_time(samp_date_time) +
shadow_mark()
figure_1 <- animate(figure_1, duration = 10, width = 500, height = 500, renderer = gifski_renderer(loop = TRUE))
figure_1 # NOTE: print(figure_1) works to show it in the viewer, but it wont knit the gif
NOTE: You might get this error: “Error in transform_path(all_frames, states[[i]], ease, nframes[i], !!id, : transformr is required to tween paths and lines”
anim_save(here("figures", "figure_1.gif"), figure_1)
figure_2 <- ts_data %>%
filter( compound == "compound_1") %>%
group_by(treatment, year, month) %>%
summarise(mean_concentration = mean(concentration, na.rm = TRUE)) %>%
ggplot() +
geom_line(aes(x = month, y = mean_concentration, colour = treatment)) +
scale_x_continuous(breaks = seq(1,12, by = 1)) +
theme_pepe() +
theme(legend.position = "bottom") +
labs(x = "Month",
y = "Concentration") +
# ggannimate sections
transition_reveal(along = month)
## `summarise()` regrouping output by 'treatment', 'year' (override with `.groups` argument)
figure_2 <- animate(figure_2, duration = 10, width = 500, height = 500, renderer = gifski_renderer(loop = TRUE))
figure_2
anim_save(here("figures", "figure_2.gif"), figure_2)
ts_data %>%
filter( compound == "compound_1") %>%
ggplot() +
facet_wrap(~month) +
geom_boxplot(aes(x = treatment, y = concentration)) +
theme_pepe()
#
figure_3 <- ts_data %>%
filter( compound == "compound_1") %>%
ggplot() +
geom_boxplot(aes(x = treatment, y = concentration, colour = treatment)) +
geom_jitter(aes(x = treatment, y = concentration, colour = treatment), alpha = 0.4) +
scale_colour_brewer(palette = "Set1") +
theme_pepe() +
#
transition_states(
month,
transition_length = 2,
state_length = 1
) +
labs(x = "Treatment",
y = "Concentration",
title = "Month: {closest_state}") +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')
figure_3 <- animate(figure_3, duration = 10, width = 500, height = 500, renderer = gifski_renderer(loop = TRUE))
figure_3 # NOTE: print(figure_3) works to show it in the viewer, but it wont knit the gif
anim_save(here("figures", "figure_3.gif"), figure_3)
plotlyfigure_4 <- ts_data %>%
filter( compound == "compound_1") %>%
ggplot() +
geom_point(aes(x = samp_date_time, y = concentration, colour = treatment)) +
theme_pepe()
figure_4
ggplotly(figure_4)